package com.ztsoft.user.pojo.entity.dynamic;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ztsoft.user.pojo.entity.user.BaseEntity;
import com.ztsoft.user.pojo.enums.ConditionEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.*;

@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("t_query_detail")
@EqualsAndHashCode(callSuper = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class QueryDetail extends BaseEntity {
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;// '主键'

    //对应保存查询id
    private String queryId;
    //字典编码
    private String dictCode;
    //保存的值
    private String content;
    //对应key
    private String fieldsName;
    //运算符
    private String operator;
    //输入框类型
    private String fieldType;


    /**
     * 创建时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 修改时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date modifyTime;
    /**
     * 创建id
     */
    private String createId;
    /**
     * 修改id
     */
    private String modifyId;
    /**
     * 是否删除
     */
    private Integer isDelete;

    @TableField(exist = false)
    private List<Map<String, String>> matchingTypeList = setMatchingTypeList();

    public List<Map<String, String>> setMatchingTypeList() {
        List<Map<String, String>> list = new ArrayList<>();
        ConditionEnum[] conditionEnums = ConditionEnum.values();
        for (ConditionEnum conditionEnum : conditionEnums) {
            Map<String, String> map = new HashMap<>();
            map.put("label", conditionEnum.getLabel());
            map.put("value", conditionEnum.getValue());
            list.add(map);
        }
        return list;
    }
}
